<?php
global $_RQ,$_AR;
$userid=$this->checklogin();
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['id']){
	$_SESSION['hotelid']=$_RQ['id'];
}
$hotelid=$_SESSION['hotelid'];
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_SESSION['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'hotelid'=>$hotelid,'userid'=>$userid);
    $fields=array('id','name','uid');
    $orderby='id desc';
	$total='';
	$return['list']=pdo_getslice('jy_jd_manage',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'店员管理'),
			array('op'=>'edit','title'=>'添加店员'),
		),
		'list'=>array('data'=>'list','list'=>array(
			'0'=>array('name'=>'name','title'=>'名称','type'=>'string'),
			'1'=>array('name'=>'uid','title'=>'uid','type'=>'string'),		
		)),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
	$item=pdo_get('jy_jd_manage',array('id'=>$id));
	}else{
		$item=array();
	}
    $return['item']=$item;	
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'店员设置',
		'tabs'=>array(
			array('op'=>'list','title'=>'店员管理'),
			array('op'=>'edit','title'=>'添加店员')
		),
		'edit'=>array(
			array('name'=>'name','title'=>'名称','type'=>'string'),
			array('name'=>'uid','title'=>'uid','type'=>'string','help'=>'填写会员中心的会员id'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array_fields(array('name','uid'),$postdata);
	$data['userid']=$userid;
	$id=intval($postdata['id']);
			if($id){
				pdo_update('jy_jd_manage',$data,array('id'=>$id));
				exi('设置成功！','','/manage.hotel/');
			}else{
			    $data['uniacid']=$_SESSION['uniacid'];
				$data['hotelid']=$_SESSION['hotelid'];
				pdo_insert('jy_jd_manage',$data);
				exi('添加成功！','','/manage.hotel/');
			}
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_jd_manage',array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_jd_manage',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}
?>